/*
 * 英才汇硕信息科技有限公司 拥有本软件版权 2021 并保留所有权利。
 * Copyright 2021, YCHS Information&Science Technology Co.,Ltd,
 * All rights reserved.
 */
package com.yckj.lawyermanager.dongao.entity;

import lombok.Data;

/**
 * 律师实体类
 * @author wuzhijun
 * @version 1.0
 */
@Data
public class Lawyer {
    int lawyerid;
    String lawyername;
    String nation;
    String gender;
    String birthday;
    String school;
}

/*
 * 英才汇硕信息科技有限公司 拥有本软件版权 2021 并保留所有权利。
 * Copyright 2021, YCHS Information&Science Technology Co.,Ltd,
 * All rights reserved.
 */
package com.yckj.lawyermanager.dongao.controller;

import com.yckj.lawyermanager.dongao.entity.Lawyer;
import com.yckj.lawyermanager.dongao.service.LawyerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 律师控制器
 * @author wuzhijun
 * @version 1.0
 */
@Controller
public class LawyerController {
    @Autowired
    LawyerService lawyerService;

    @RequestMapping("/del")
    public String delLawyer(int lawyerid){
         lawyerService.removeLawyer(lawyerid);
        return "../static/success";
    }

    @RequestMapping("/show")
    public String showLawyer(Model model){
        List<Lawyer> lawyerList = lawyerService.findLawyer();
        // 把lawyerList传递到网页上
        model.addAttribute("lawList", lawyerList);
        // displayLawyer 代表网页displayLawyer.html
        return "../static/displayLawyer";
    }

    @RequestMapping("/addLawyer")
    public String addLawyer(Lawyer lawyer) {
        lawyerService.addLawyer(lawyer);
        //successs代表网页success.html
        return "../static/success";
    }
}

/*
 * 英才汇硕信息科技有限公司 拥有本软件版权 2021 并保留所有权利。
 * Copyright 2021, YCHS Information&Science Technology Co.,Ltd,
 * All rights reserved.
 */
package com.yckj.lawyermanager.dongao.mapper;

import com.yckj.lawyermanager.dongao.entity.Lawyer;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 律师档案操作：创建、查询、修改、删除
 * @author wuzhijun
 * @version 1.0
 */
@Mapper
public interface LawyerMapper {
    public int deleteLawyer(int lawyerid);
    /**
     * 查询所有律师
     * @return 律师集合
     */
    public List<Lawyer> selectLawyer();
    /**
     * 添加律师（创建律师档案）
     * @param lawyer 包含律师信息的对象
     * @return 创建成功返回1，否则返回0
     */
    public int insertLawyer(Lawyer lawyer);
}

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yckj.lawyermanager.dongao.mapper.LawyerMapper">
    <insert id="insertLawyer">
        INSERT INTO lawyer(lawyername,gender,nation,school,birthday)
            VALUES(#{lawyername},#{gender},#{nation},#{school},#{birthday})
    </insert>
    <delete id="deleteLawyer">
        DELETE FROM lawyer WHERE lawyerid=#{lawyerid}
    </delete>
    <select id="selectLawyer" resultType="com.yckj.lawyermanager.dongao.entity.Lawyer">
        SELECT * FROM lawyer
    </select>
</mapper>

/*
 * 英才汇硕信息科技有限公司 拥有本软件版权 2021 并保留所有权利。
 * Copyright 2021, YCHS Information&Science Technology Co.,Ltd,
 * All rights reserved.
 */
package com.yckj.lawyermanager.dongao.service;

import com.yckj.lawyermanager.dongao.entity.Lawyer;

import java.util.List;

/**
 * 律师档案业务接口
 * @author wuzhijun
 * @version 1.0
 */
public interface LawyerService {
    public int removeLawyer(int lawyerid);
    /**
     * 查询所有律师
     * @return 律师集合
     */
    public List<Lawyer> findLawyer();
    /**
     * 添加律师
     * @param lawyer 律师对象
     * @return 添加成功返回1，否则返回0
     */
    public int addLawyer(Lawyer lawyer);
}

/*
 * 英才汇硕信息科技有限公司 拥有本软件版权 2021 并保留所有权利。
 * Copyright 2021, YCHS Information&Science Technology Co.,Ltd,
 * All rights reserved.
 */
package com.yckj.lawyermanager.dongao.service;

import com.yckj.lawyermanager.dongao.entity.Lawyer;
import com.yckj.lawyermanager.dongao.mapper.LawyerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 律师业务接口实现类
 * @author wuzhijun
 * @version 1.0
 */
@Service
public class LawyerServiceImpl implements LawyerService {
    @Autowired
    LawyerMapper lawyerMapper;

    @Override
    public int removeLawyer(int lawyerid) {
        return lawyerMapper.deleteLawyer(lawyerid);
    }

    /**
     * 查询所有律师
     *
     * @return 律师集合
     */
    @Override
    public List<Lawyer> findLawyer() {
        return lawyerMapper.selectLawyer();
    }

    /**
     * 添加律师
     *
     * @param lawyer 律师对象
     * @return 添加成功返回1，否则返回0
     */
    @Override
    public int addLawyer(Lawyer lawyer) {
        return lawyerMapper.insertLawyer(lawyer);
    }
}

